<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>在线考试平台</title>
    <link rel="shortcut icon" href="static/layui/images/exam.png" type="image/x-icon">
    <link rel="stylesheet" href="static/layui/css/font.css">
    <link rel="stylesheet" href="static/layui/css/xadmin.css">
    <script src="static/layui/lib/layui/layui.js"></script>
    <script src="static/layui/js/xadmin.js"></script>
    <script src="static/layui/js/jquery.min.js"></script>

</head>

<body class="index">
<div class="container">
    <div class="logo">
        <a href="#">在线考试平台后台管理</a>
    </div>
    <div class="left_open">
        <a><i title="展开左侧栏" class="iconfont">&#xe699;</i></a>
    </div>
    <ul class="layui-nav right" lay-filter="header-user" id="user-state">

    </ul>
</div>
<div class="left-nav">
    <div id="side-nav">
        <ul id="nav">
            <li>
                <a href="javascript:;">
                    <i class="iconfont left-nav-li" lay-tips="题库管理">&#xe723;</i>
                    <cite>题库管理</cite>
                    <i class="iconfont nav_right">&#xe697;</i></a>
                <ul class="sub-menu">
                    <li>
                        <a onclick="xadmin.add_tab('新增试题','/exam_system/question')">
                            <i class="iconfont">&#xe6a7;</i>
                            <cite>新增试题</cite></a>
                    </li>
                    <li>
                        <a onclick="xadmin.add_tab('科目列表','/exam_system/subject_list')">
                            <i class="iconfont">&#xe6a7;</i>
                            <cite>科目列表</cite></a>
                    </li>
                </ul>
            </li>
            <li>
                <a href="javascript:;">
                    <i class="iconfont left-nav-li" lay-tips="试卷管理">&#xe723;</i>
                    <cite>试卷管理</cite>
                    <i class="iconfont nav_right">&#xe697;</i></a>
                <ul class="sub-menu">
                    <li>
                        <a onclick="xadmin.add_tab('新增试卷','/exam_system/exam_paper')">
                            <i class="iconfont">&#xe6a7;</i>
                            <cite>新增试卷</cite></a>
                    </li>
                    <li>
                        <a onclick="xadmin.add_tab('试卷列表','/exam_system/exam_paper_library')">
                            <i class="iconfont">&#xe6a7;</i>
                            <cite>试卷列表</cite></a>
                    </li>
                </ul>
            </li>
            <li>
                <a href="javascript:;">
                    <i class="iconfont left-nav-li" lay-tips="考试管理">&#xe723;</i>
                    <cite>考试管理</cite>
                    <i class="iconfont nav_right">&#xe697;</i></a>
                <ul class="sub-menu">
                    <li>
                        <a onclick="xadmin.add_tab('发布考试','/exam_system/release_exam')">
                            <i class="iconfont">&#xe6a7;</i>
                            <cite>发布考试</cite></a>
                    </li>
                    <li>
                        <a onclick="xadmin.add_tab('考试列表','/exam_system/exam_list')">
                            <i class="iconfont">&#xe6a7;</i>
                            <cite>考试列表</cite></a>
                    </li>
                    <li>
                        <a onclick="xadmin.add_tab('待批阅试卷','/exam_system/wait_review_exam')">
                            <i class="iconfont">&#xe6a7;</i>
                            <cite>待批阅试卷</cite></a>
                    </li>
                </ul>
            </li>
        </ul>
    </div>
</div>
<div class="page-content">
    <div class="layui-tab tab" lay-filter="xbs_tab" lay-allowclose="false">
        <ul class="layui-tab-title">
            <li class="home">
                <i class="layui-icon">&#xe68e;</i>首页
            </li>
        </ul>
        <div class="layui-unselect layui-form-select layui-form-selected" id="tab_right">
            <dl>
                <dd data-type="this">关闭当前</dd>
                <dd data-type="other">关闭其它</dd>
                <dd data-type="all">关闭全部</dd>
            </dl>
        </div>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <iframe src='welcome' frameborder="0" scrolling="yes" class="x-iframe"></iframe>
            </div>
        </div>
        <div id="tab_show"></div>
    </div>
</div>
<div class="page-content-bg"></div>
</body>

<script>
    layui.use(['element', "form", 'jquery', 'layer'], function () {
        const form = layui.form;
        const $ = layui.jquery;
        const layer = layui.layer;
        const element = layui.element;
        header(element)
        var active = {
            //在这里给active绑定事件，后面可通过active调用这些事件
            tabDeleteAll:function(ids){//删除所有
                $.each(ids,function(i,item){
                    element.tabDelete("xbs_tab",item);//ids是一个数组，里面存放了多个id，调用tabDelete方法分别删除
                })
            }
        };

        var tabtitle = $(".layui-tab-title li");
        var ids = new Array();
        $.each(tabtitle, function (i) {
            ids[i] = $(this).attr("lay-id");
        });
        active.tabDeleteAll(ids);
    });

    function header(element) {
        var user_json = JSON.parse(sessionStorage.getItem("userJson"));
        var text = ""
        if (user_json === null) {
            location.href = '/exam_system/';
        } else {
            text += "<li class=\"layui-nav-item\">" +
                "                    <a href=\"javascript:;\">" + user_json.u_name + "</a>" +
                "                    <dl class=\"layui-nav-child\">" +
                "                        <dd><a onclick='modify_psw()'>修改密码</a></dd>" +
                "                        <dd><a onclick='user_quit()'>退出</a></dd>" +
                "                    </dl>" +
                "                </li>"
            $("#user-state").html(text)
        }
        element.render('header-user')
    }

    function user_quit() {
        sessionStorage.clear("userJson");
        location.href = '/exam_system/';
    }
    function modify_psw() {
        layui.use(['element', "form", 'jquery', 'layer'], function () {
            const form = layui.form;
            const $ = layui.jquery;
            const layer = layui.layer;
            const element = layui.element;
            var text = "<form class=\"layui-form layui-form-pane\" action=\"\">" +
                "    <div class=\"layui-form-item\">" +
                "        <label class=\"layui-form-label\">旧密码</label>" +
                "        <div class=\"layui-input-block\">" +
                "            <input type=\"text\" name=\"o_psw\" id='o_psw' autocomplete=\"off\" placeholder=\"请输入旧密码\"" +
                "                   class=\"layui-input\">" +
                "        </div>" +
                "    </div>" +
                "    <div class=\"layui-form-item\">" +
                "        <label class=\"layui-form-label\">新密码</label>" +
                "        <div class=\"layui-input-block\">" +
                "            <input type=\"password\" name=\"n_psw\" id='n_psw' autocomplete=\"off\" placeholder=\"请输入新密码\"" +
                "                   class=\"layui-input\">" +
                "        </div>" +
                "    </div>" +
                "    <div class=\"layui-form-item\">" +
                "        <label class=\"layui-form-label\">确认新密码</label>" +
                "        <div class=\"layui-input-block\">" +
                "            <input type=\"password\" name=\"re_psw\" id='re_psw' autocomplete=\"off\" placeholder=\"请输入确认密码\"" +
                "                   class=\"layui-input\">" +
                "        </div>" +
                "    </div>" +
                "</form>"
            var index = layer.open({
                type: 1,
                title: "修改密码",
                closeBtn: 1,
                shadeClose: true,
                btn: '确定',
                yes: function (index, layero) {
                    var o_psw = $("#o_psw").val();
                    var n_psw = $("#n_psw").val();
                    var re_psw = $("#re_psw").val();
                    var user_json = JSON.parse(sessionStorage.getItem("userJson"));
                    var u_psw=user_json.u_psw;
                    var u_id=user_json.u_id;
                    if (u_psw!==o_psw){
                        layer.msg("旧密码错误 请重新输入", {icon: 5, time: 1000});
                        return false;
                    }
                    if (n_psw !== re_psw) {
                        layer.msg("两次密码不一致", {icon: 5, time: 1000});
                        return false;
                    }
                    $.ajax({
                        url: 'update_user_psw_by_u_id',
                        dataType: "json",//数据格式
                        type: "post",//请求方式
                        cache: false,
                        data: {
                            u_id: u_id,
                            u_psw: n_psw,
                        },
                        success: function (data) {
                            if (data.code === 200) {
                                layer.msg(data.message, {icon: 6}, function () {
                                    sessionStorage.clear("userJson");
                                    location.href = '/exam_system/';
                                });
                            } else {
                                layer.msg(data.message, {icon: 5, time: 1000});
                            }
                        },
                        error: function (e) {
                            alert("出现错误！！");
                        }
                    });
                },
                area: ['500px', '400px'],
                content: text
            });
        });
    }
</script>

</html>